package com.bytedance.scenedemo.extreme_case;

import com.bytedance.scene.Scene;
import com.bytedance.scene.animation.animatorexecutor.HorizontalTransitionAnimatorExecutor;
import com.bytedance.scene.group.GroupScene;
import com.bytedance.scene.interfaces.PushOptions;
import com.bytedance.scene.ktx.SceneExtensions;
import com.bytedance.scenedemo.ResourceTable;
import com.bytedance.scenedemo.benchmark.BenchmarkSamples;
import com.bytedance.scenedemo.utility.ColorUtil;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.IntentParams;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.ScrollView;
import ohos.agp.components.Text;

import java.sql.SQLOutput;

public class Case0Scene extends GroupScene {

    @Override
    public ComponentContainer onCreateView(LayoutScatter inflater, ComponentContainer container, Intent savedInstanceState) {
        return (ComponentContainer) inflater.parse(ResourceTable.Layout_case_basic_layout, container, false);
    }

    @Override
    public void onViewCreated(Component layout, Intent intent) {
        super.onViewCreated(layout, intent);
        Text textHint = (Text) layout.findComponentById(ResourceTable.Id_text_case0scene_hint);
        ScrollView svMain = (ScrollView) layout.findComponentById(ResourceTable.Id_sv_push_pop_basic_usage_main);
        textHint.setText(Case0Scene.class.getName());
        int value = 0;
        if (getArguments() != null) {
            value = (int) getArguments().getParam("value");
        }
        svMain.setBackground(ColorUtil.getMaterialColor(value));

        Button btnPushAndPop1 = (Button) layout.findComponentById(ResourceTable.Id_case_push_pop_btn_1);
        btnPushAndPop1.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                PushOptions options=new PushOptions.Builder()
                        .setAnimation(new HorizontalTransitionAnimatorExecutor())
                        .build();
                for (int i = 0; i <= 99; i++) {
                    SceneExtensions.getNavigationScene(Case0Scene.this).push(EmptyScene.class,null, options);
                    SceneExtensions.requireNavigationScene(Case0Scene.this).pop();
                }
            }
        });
        Button btnPushAndPop2 = (Button) layout.findComponentById(ResourceTable.Id_case_push_pop_btn_2);
        btnPushAndPop2.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                PushOptions options=new PushOptions.Builder()
                        .setAnimation(new HorizontalTransitionAnimatorExecutor())
                        .build();
                for (int i = 0; i <= 99; i++) {
                    SceneExtensions.getNavigationScene(Case0Scene.this).push(EmptyScene.class,null, options);
                }
                for (int i = 0; i <= 99; i++) {
                    SceneExtensions.requireNavigationScene(Case0Scene.this).pop();
                }
            }
        });
        Button btnPushAndPop3 = (Button) layout.findComponentById(ResourceTable.Id_case_push_pop_btn_3);
        btnPushAndPop3.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                PushOptions options = new PushOptions.Builder()
                        .setAnimation(new HorizontalTransitionAnimatorExecutor())
                        .build();
                IntentParams intentParams = new IntentParams();
                intentParams.setParam("value",2);
                intentParams.setParam("type",0);
                SceneExtensions.getNavigationScene(Case0Scene.this).push(EmptyScene0.class,intentParams, options);
                for (int i = 0; i <= 98; i++) {
                    IntentParams intentParams2 = new IntentParams();
                    intentParams2.setParam("value",1);
                    intentParams2.setParam("type",0);
                    SceneExtensions.requireNavigationScene(Case0Scene.this).push(EmptyScene.class,intentParams2, options);
                }
                for (int i = 0; i <= 98; i++) {
                    SceneExtensions.requireNavigationScene(Case0Scene.this).pop();
                }
            }
        });
    }

    @Override
    public void onAbilityCreated(Intent intent) {
        super.onAbilityCreated(intent);
    }
}
